from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-12 14:06:05.596436
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 12, Feb, 2021
Time: 14:06:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0703
Nobs: 200.000 HQIC: -46.9539
Log likelihood: 2291.36 FPE: 2.22668e-21
AIC: -47.5545 Det(Omega_mle): 1.43534e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.469981 0.140600 3.343 0.001
L1.Burgenland 0.083018 0.072325 1.148 0.251
L1.Kärnten -0.216743 0.060996 -3.553 0.000
L1.Niederösterreich 0.129053 0.167922 0.769 0.442
L1.Oberösterreich 0.241909 0.147624 1.639 0.101
L1.Salzburg 0.201454 0.077818 2.589 0.010
L1.Steiermark 0.102208 0.104735 0.976 0.329
L1.Tirol 0.148775 0.070208 2.119 0.034
L1.Vorarlberg -0.002595 0.064596 -0.040 0.968
L1.Wien -0.143273 0.141362 -1.014 0.311
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488208 0.170375 2.865 0.004
L1.Burgenland 0.014831 0.087642 0.169 0.866
L1.Kärnten 0.360728 0.073913 4.880 0.000
L1.Niederösterreich 0.136514 0.203483 0.671 0.502
L1.Oberösterreich -0.136985 0.178887 -0.766 0.444
L1.Salzburg 0.197040 0.094297 2.090 0.037
L1.Steiermark 0.207411 0.126915 1.634 0.102
L1.Tirol 0.138881 0.085076 1.632 0.103
L1.Vorarlberg 0.172177 0.078276 2.200 0.028
L1.Wien -0.566746 0.171298 -3.309 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313692 0.062538 5.016 0.000
L1.Burgenland 0.106180 0.032170 3.301 0.001
L1.Kärnten -0.018767 0.027130 -0.692 0.489
L1.Niederösterreich 0.071598 0.074690 0.959 0.338
L1.Oberösterreich 0.290499 0.065662 4.424 0.000
L1.Salzburg -0.002740 0.034612 -0.079 0.937
L1.Steiermark -0.015691 0.046585 -0.337 0.736
L1.Tirol 0.086853 0.031228 2.781 0.005
L1.Vorarlberg 0.110195 0.028732 3.835 0.000
L1.Wien 0.064238 0.062876 1.022 0.307
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.221973 0.070421 3.152 0.002
L1.Burgenland -0.011182 0.036225 -0.309 0.758
L1.Kärnten 0.022917 0.030550 0.750 0.453
L1.Niederösterreich 0.045986 0.084105 0.547 0.585
L1.Oberösterreich 0.381245 0.073939 5.156 0.000
L1.Salzburg 0.093230 0.038976 2.392 0.017
L1.Steiermark 0.181640 0.052458 3.463 0.001
L1.Tirol 0.040223 0.035164 1.144 0.253
L1.Vorarlberg 0.089570 0.032354 2.768 0.006
L1.Wien -0.067590 0.070802 -0.955 0.340
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.518783 0.141211 3.674 0.000
L1.Burgenland 0.055355 0.072640 0.762 0.446
L1.Kärnten 0.013676 0.061261 0.223 0.823
L1.Niederösterreich -0.034739 0.168652 -0.206 0.837
L1.Oberösterreich 0.150574 0.148266 1.016 0.310
L1.Salzburg 0.062301 0.078156 0.797 0.425
L1.Steiermark 0.126005 0.105191 1.198 0.231
L1.Tirol 0.212270 0.070513 3.010 0.003
L1.Vorarlberg 0.026783 0.064877 0.413 0.680
L1.Wien -0.121047 0.141976 -0.853 0.394
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160412 0.099445 1.613 0.107
L1.Burgenland -0.018110 0.051155 -0.354 0.723
L1.Kärnten -0.011052 0.043141 -0.256 0.798
L1.Niederösterreich 0.109844 0.118769 0.925 0.355
L1.Oberösterreich 0.388035 0.104413 3.716 0.000
L1.Salzburg -0.018644 0.055039 -0.339 0.735
L1.Steiermark -0.022900 0.074078 -0.309 0.757
L1.Tirol 0.190365 0.049657 3.834 0.000
L1.Vorarlberg 0.037358 0.045688 0.818 0.414
L1.Wien 0.192021 0.099983 1.921 0.055
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231051 0.127714 1.809 0.070
L1.Burgenland 0.063442 0.065697 0.966 0.334
L1.Kärnten -0.038393 0.055406 -0.693 0.488
L1.Niederösterreich -0.037913 0.152532 -0.249 0.804
L1.Oberösterreich -0.090494 0.134095 -0.675 0.500
L1.Salzburg 0.037592 0.070686 0.532 0.595
L1.Steiermark 0.393838 0.095136 4.140 0.000
L1.Tirol 0.490070 0.063774 7.685 0.000
L1.Vorarlberg 0.166288 0.058676 2.834 0.005
L1.Wien -0.214186 0.128406 -1.668 0.095
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.073700 0.154014 0.479 0.632
L1.Burgenland 0.030507 0.079225 0.385 0.700
L1.Kärnten -0.085679 0.066815 -1.282 0.200
L1.Niederösterreich 0.238276 0.183942 1.295 0.195
L1.Oberösterreich -0.008451 0.161708 -0.052 0.958
L1.Salzburg 0.235811 0.085242 2.766 0.006
L1.Steiermark 0.141562 0.114727 1.234 0.217
L1.Tirol 0.070019 0.076906 0.910 0.363
L1.Vorarlberg 0.047627 0.070759 0.673 0.501
L1.Wien 0.262174 0.154848 1.693 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590877 0.083043 7.115 0.000
L1.Burgenland -0.031907 0.042718 -0.747 0.455
L1.Kärnten -0.009688 0.036026 -0.269 0.788
L1.Niederösterreich -0.019843 0.099180 -0.200 0.841
L1.Oberösterreich 0.294677 0.087192 3.380 0.001
L1.Salzburg 0.017335 0.045962 0.377 0.706
L1.Steiermark 0.002967 0.061860 0.048 0.962
L1.Tirol 0.077562 0.041467 1.870 0.061
L1.Vorarlberg 0.130593 0.038153 3.423 0.001
L1.Wien -0.046882 0.083493 -0.562 0.574
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.136678 0.037179 0.200930 0.256391 0.064955 0.097165 -0.055310 0.166311
Kärnten 0.136678 1.000000 0.009383 0.192204 0.166749 -0.114850 0.154241 0.012968 0.319037
Niederösterreich 0.037179 0.009383 1.000000 0.308131 0.080579 0.214698 0.127056 0.053374 0.354540
Oberösterreich 0.200930 0.192204 0.308131 1.000000 0.297333 0.292789 0.105463 0.076711 0.136221
Salzburg 0.256391 0.166749 0.080579 0.297333 1.000000 0.148667 0.061186 0.085708 -0.004347
Steiermark 0.064955 -0.114850 0.214698 0.292789 0.148667 1.000000 0.103668 0.096312 -0.099554
Tirol 0.097165 0.154241 0.127056 0.105463 0.061186 0.103668 1.000000 0.161526 0.150342
Vorarlberg -0.055310 0.012968 0.053374 0.076711 0.085708 0.096312 0.161526 1.000000 0.051490
Wien 0.166311 0.319037 0.354540 0.136221 -0.004347 -0.099554 0.150342 0.051490 1.000000